<?php

namespace App\depository;

use App\Enum\CommonEnum;
use App\Enum\TeamsEnum;
use App\Models\ManageMapExtraModel;
use App\Models\ManageMapModel;

class ManageMapExtraDep
{
    public $model;

    public function __construct()
    {
        $this->model = new ManageMapExtraModel();
    }

    public function first($id){
        return $this->model->where('id', $id)->first();
    }

    public function firstByTeamIdMapId($teamId,$mapId){
        return $this->model->where('gh_id', $teamId)->where('manage_map_id',$mapId)->first();

    }

    public function list($param)
    {
        $res = $this->model
            ->when(!empty($param['id']), function ($query) use ($param) {
                return $query->where("id",$param['id']);
            })
            ->when(!empty($param['map_name']), function ($query) use ($param) {
                return $query->where("map_name", 'like', "%{$param['map_name']}%");
            })
            ->when(!empty($param['zh_name']), function ($query) use ($param) {
                return $query->where("zh_name", 'like', "%{$param['zh_name']}%");
            })
            ->orderBy('id', 'desc')
            ->paginate($param['per_page'], ['*'], 'page', $param['current_page']);;
        return $res;
    }

    public function getByMapIds($teamId,$mapIds){
        $res = $this->model->where('gh_id',$teamId)->whereIn('manage_map_id',$mapIds)->get();
        return $res;
    }

    public function add($data)
    {
        $res = $this->model->insert($data);
        return $res;
    }

    public function upd($id, $data)
    {
        $res = $this->model->where('id', $id)->update($data);
        return $res;
    }

    public function del($id)
    {
        $res = $this->model->where('id', $id)->delete();
        return $res;
    }

}
